//
//  WPTransTableViewCell.m
//  ZhongChouPingTai
//
//  Created by WeiPan on 16/4/7.
//  Copyright © 2016年 WPJoe. All rights reserved.
//

#import "WPTransTableViewCell.h"

@interface WPTransTableViewCell ()
@property (nonatomic, strong) UIView * backView;/**< 白色背景 */
@property (nonatomic, strong) UILabel * titleLabel;/**< 标题 */
@property (nonatomic, strong) UIView * grayView;/**< 类型灰色背景 */
@property (nonatomic, strong) UILabel * typeLabel;/**< 类型 */
@property (nonatomic, strong) UILabel * positionLabel;/**< 位置 */
@property (nonatomic, strong) UITextField * buyinPriceTextField;/**< 买入价格 */
@property (nonatomic, strong) UITextField * sellPriceTextField;/**< 卖出价格 */
@property (nonatomic, strong) UIButton * revokeBtn;/**< 撤销 */
- (void)initializeAppearance;/**< 一般界面初始化 */


@end
@implementation WPTransTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self initializeAppearance];
    }
    return self;
}

#pragma mark - init
- (void)initializeAppearance {
    self.backgroundColor = [UIColor clearColor];
    [self addSubview:self.backView];
}
#pragma mark - responds events
- (void)respondsToRevokeBtn {
    if (_delegate && [_delegate respondsToSelector:@selector(revokeTransWithModel:andWithIndex:)]) {
        [_delegate revokeTransWithModel:_model andWithIndex:_indexPath];
    }
}
#pragma mark - setter
- (void)setModel:(WPTransCancelModel *)model {
    _model = model;
    _titleLabel.text = model.goodsName;
    if ([model.saleType isEqualToString:@"SINGLE"]) {
        _typeLabel.text = @"单人票";
    }
    if ([model.saleType isEqualToString:@"PAIR"]) {
        _typeLabel.text = @"情侣票";
    }
    if ([model.saleType isEqualToString:@"COMBINATION"]) {
        _typeLabel.text = @"组合票";
    }
    _positionLabel.text = model.ticketName;
    _buyinPriceTextField.text = [NSString stringWithFormat:@"%@", model.gerBuyMoent];
    _sellPriceTextField.text = [NSString stringWithFormat:@"%@", model.salePrice];
}
#pragma mark - getter
- (UIView *)backView {
    if (!_backView) {
        _backView = ({
            UIView * view = [[UIView alloc]initWithFrame:CGRectMake(5*DHFlexibleHorizontalMutiplier(), 10*DHFlexibleHorizontalMutiplier(), 310*DHFlexibleHorizontalMutiplier(), 150*DHFlexibleHorizontalMutiplier())];
            view.layer.cornerRadius = 5*DHFlexibleHorizontalMutiplier();
            view.layer.masksToBounds = YES;
            view.layer.borderWidth = 0.5;
            view.layer.borderColor = COLOR_RGB(163, 163, 163, 1).CGColor;
            view.backgroundColor = [UIColor whiteColor];
            [view addSubview:self.titleLabel];
            [view addSubview:self.grayView];
            [view addSubview:self.buyinPriceTextField];
            [view addSubview:self.sellPriceTextField];
            [view addSubview:self.revokeBtn];
            view;
        });
    }
    return _backView;
}
- (UILabel *)titleLabel {
    if (!_titleLabel) {
        _titleLabel = ({
            UILabel * lab = [[UILabel alloc]initWithFrame:CGRectMake(8*DHFlexibleHorizontalMutiplier(), 0, 300*DHFlexibleHorizontalMutiplier(), 35*DHFlexibleHorizontalMutiplier())];
            lab.font = [UIFont systemFontOfSize:12*DHFlexibleHorizontalMutiplier()];
            lab.textColor = COLOR_RGB(61, 61, 61, 1);
            
            lab;
        });
    }
    return _titleLabel;
}
- (UIView *)grayView {
    if (!_grayView) {
        _grayView = ({
            UIView * view = [[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(self.titleLabel.frame), 310*DHFlexibleHorizontalMutiplier(), 30*DHFlexibleHorizontalMutiplier())];
            view.backgroundColor = BGCOLOR;
            [view addSubview:self.typeLabel];
            [view addSubview:self.positionLabel];
            view;
        });
    }
    return _grayView;
}
- (UILabel *)typeLabel {
    if (!_typeLabel) {
        _typeLabel = ({
            UILabel * lab = [[UILabel alloc]initWithFrame:CGRectMake(9*DHFlexibleHorizontalMutiplier(), 5*DHFlexibleHorizontalMutiplier(), 40*DHFlexibleHorizontalMutiplier(), 20*DHFlexibleHorizontalMutiplier())];
            lab.layer.cornerRadius = 3*DHFlexibleHorizontalMutiplier();
            lab.layer.masksToBounds = YES;
            lab.backgroundColor = COLOR_RGB(234, 27, 47, 1);
            lab.textColor = [UIColor whiteColor];
            lab.textAlignment = NSTextAlignmentCenter;
            lab.font = [UIFont systemFontOfSize:10*DHFlexibleHorizontalMutiplier()];
            lab;
        });
    }
    return _typeLabel;
}
- (UILabel *)positionLabel {
    if (!_positionLabel) {
        _positionLabel = ({
            UILabel * lab = [[UILabel alloc]initWithFrame:CGRectMake(55*DHFlexibleHorizontalMutiplier(), 0, 250*DHFlexibleHorizontalMutiplier(), 30*DHFlexibleHorizontalMutiplier())];
            lab.font = [UIFont systemFontOfSize:13*DHFlexibleHorizontalMutiplier()];
            lab.textColor = COLOR_RGB(73, 73, 73, 1);
            lab;
        });
    }
    return _positionLabel;
}
- (UITextField *)buyinPriceTextField {
    if (!_buyinPriceTextField) {
        _buyinPriceTextField = ({
            UITextField * text = [[UITextField alloc]initWithFrame:CGRectMake(8*DHFlexibleHorizontalMutiplier(), CGRectGetMaxY(self.grayView.frame), 146*DHFlexibleHorizontalMutiplier(), 45*DHFlexibleHorizontalMutiplier())];
            text.leftViewMode = UITextFieldViewModeAlways;
            UILabel * lab = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 70*DHFlexibleHorizontalMutiplier(), 45*DHFlexibleHorizontalMutiplier())];
            lab.textColor = COLOR_RGB(113, 113, 113, 1);
            lab.font = [UIFont  systemFontOfSize:12*DHFlexibleHorizontalMutiplier()];
            lab.text = @"买入价：¥";
            text.leftView = lab;
            text.textColor = COLOR_RGB(113, 113, 113, 1);
            text.font = [UIFont systemFontOfSize:14*DHFlexibleHorizontalMutiplier()];
            text.userInteractionEnabled = NO;
            text;
        });
    }
    return _buyinPriceTextField;
}
- (UITextField *)sellPriceTextField {
    if (!_sellPriceTextField) {
        _sellPriceTextField = ({
            UITextField * text = [[UITextField alloc]initWithFrame:CGRectMake(154*DHFlexibleHorizontalMutiplier(), CGRectGetMaxY(self.grayView.frame), 146*DHFlexibleHorizontalMutiplier(), 45*DHFlexibleHorizontalMutiplier())];
            text.leftViewMode = UITextFieldViewModeAlways;
            UILabel * lab = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 70*DHFlexibleHorizontalMutiplier(), 45*DHFlexibleHorizontalMutiplier())];
            lab.textColor = COLOR_RGB(113, 113, 113, 1);
            lab.font = [UIFont  systemFontOfSize:12*DHFlexibleHorizontalMutiplier()];
            lab.text = @"转卖价：¥";
            text.leftView = lab;
            text.textColor = COLOR_RGB(113, 113, 113, 1);
            text.font = [UIFont systemFontOfSize:14*DHFlexibleHorizontalMutiplier()];
            text.userInteractionEnabled = NO;
            text;
        });
    }
    return _sellPriceTextField;
}
- (UIButton *)revokeBtn {
    if (!_revokeBtn) {
        _revokeBtn = ({
            UIButton * btn = [UIButton buttonWithType:UIButtonTypeCustom];
            btn.frame = CGRectMake(245*DHFlexibleHorizontalMutiplier(), CGRectGetMaxY(self.sellPriceTextField.frame)+7.5*DHFlexibleHorizontalMutiplier(), 50*DHFlexibleHorizontalMutiplier(), 25*DHFlexibleHorizontalMutiplier());
            [btn setTitle:@"撤回转卖" forState:UIControlStateNormal];
            [btn setTitleColor:COLOR_RGB(113, 113, 113, 1) forState:UIControlStateNormal];
            btn.titleLabel.font = [UIFont systemFontOfSize:10*DHFlexibleHorizontalMutiplier()];
            [btn addTarget:self action:@selector(respondsToRevokeBtn) forControlEvents:UIControlEventTouchUpInside];
            btn.layer.cornerRadius = 3*DHFlexibleHorizontalMutiplier();
            btn.layer.borderWidth = 0.5;
            btn.layer.borderColor = COLOR_RGB(163, 163, 163, 1).CGColor;
            btn;
        });
    }
    return _revokeBtn;
}
- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
